import { FairyGUI } from 'csharp';
import EGlist from '../../fgui/common/EGlist';
/**
 * 
 * @author clong 2020.11.01
 */
export default class FairyUtils{

    /**
	  * 声明容器对应变量
	  * @param parent 		容器
	  * @param thisObject 	this对象
	  */
	public static setVar(parent: FairyGUI.GComponent, thisObject: any, btns: Array<FairyGUI.GButton> = null): void {

		if (parent != null && thisObject != null) {
			let disObj: FairyGUI.GObject;
			for (let i: number = 0; i < parent.numChildren; i++) { //objects
				disObj = parent.GetChildAt(i);
				if (disObj.name == "icon" || disObj.name == "title") {
					continue;
				}				
				if (thisObject != null) {
					thisObject[disObj.name] = disObj;
				}
				if (disObj.name && disObj.name.indexOf("eglist_") == 0 && disObj instanceof FairyGUI.GList) {
					thisObject[disObj.name] = new EGlist(disObj.asList, thisObject);
				}
				if (btns != null && disObj instanceof FairyGUI.GButton) {
					btns.push(disObj);
				}
			}

			// for (let i: number = 0; i < parent._transitions.length; i++) {
			// 	let transObj: FairyGUI.Transition;
			// 	transObj = parent._transitions[i];
			// 	thisObject[transObj.name] = transObj;
			// }
		}
	}
}